]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
messageTray: Only take params in `Notification` constructor
authorJulian Sparber <julian@sparber.net>
Wed, 14 Feb 2024 10:11:47 +0000 (11:11 +0100)
committerFlorian Müllner <fmuellner@gnome.org>
Sun, 3 Mar 2024 01:33:16 +0000 (01:33 +0000)
Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/3173>

13 files changed:
js/ui/components/autorunManager.js
js/ui/components/networkAgent.js
js/ui/extensionSystem.js
js/ui/main.js
js/ui/messageTray.js
js/ui/notificationDaemon.js
js/ui/overview.js
js/ui/screenshot.js
js/ui/shellMountOperation.js
js/ui/status/network.js
js/ui/status/thunderbolt.js
js/ui/windowAttentionHandler.js
tests/shell/basic.js

index 1b8f718952d4fa9d63c7554df92d90ba93dce8c5..40dd5858d6cbe61dab633310e5ace8c57ea697e5 100644 (file)
@@ -187,10 +187,10 @@ class AutorunDispatcher {
             return;
 
         const source = MessageTray.getSystemSource();
-        const notification = new MessageTray.Notification(
+        const notification = new MessageTray.Notification({
             source,
-            mount.get_name()
-        );
+            title: mount.get_name(),
+        });
         notification.connect('activate', () => {
             const app = Gio.app_info_get_default_for_type('inode/directory', false);
             startAppForMount(app, mount);
index bab13b184d0655883eaa991d22a38da446b55a15..aad9ecf4fd4bd850b94d3f676d3de809010e2155 100644 (file)
@@ -782,7 +782,7 @@ class NetworkAgent {
         }
 
         const source = MessageTray.getSystemSource();
-        const notification = new MessageTray.Notification(source, title, body);
+        const notification = new MessageTray.Notification({source, title, body});
         notification.iconName = 'dialog-password-symbolic';
 
         notification.connect('activated', () => {
index a74e08bac219064e4ef3e03e388a99bc551e0741..8e4af6f15aff905c3b6a1d43ae5b226077b694ba 100644 (file)
@@ -349,9 +349,11 @@ export class ExtensionManager extends Signals.EventEmitter {
             let source = new ExtensionUpdateSource();
             Main.messageTray.add(source);
 
-            let notification = new MessageTray.Notification(source,
-                _('Extension Updates Available'),
-                _('Extension updates are ready to be installed.'));
+            const notification = new MessageTray.Notification({
+                source,
+                title: _('Extension Updates Available'),
+                body: _('Extension updates are ready to be installed.'),
+            });
             notification.connect('activated',
                 () => source.open());
             source.addNotification(notification);
index a090a76ae3067b6680e35ebcabf897b9d77775a1..8a3c177d946c41af80a8d4ecc6c91b7d4b0e3bfc 100644 (file)
@@ -274,9 +274,11 @@ async function _initializeUI() {
             return; // assume user action
 
         const source = MessageTray.getSystemSource();
-        const notification = new MessageTray.Notification(source,
-            _('System was put in unsafe mode'),
-            _('Apps now have unrestricted access'));
+        const notification = new MessageTray.Notification({
+            source,
+            title: _('System was put in unsafe mode'),
+            body: _('Apps now have unrestricted access'),
+        });
         notification.addAction(_('Undo'),
             () => (global.context.unsafe_mode = false));
         notification.setTransient(true);
@@ -614,7 +616,11 @@ export function loadTheme() {
  */
 export function notify(msg, details) {
     const source = MessageTray.getSystemSource();
-    let notification = new MessageTray.Notification(source, msg, details);
+    const notification = new MessageTray.Notification({
+        source,
+        title: msg,
+        body: details,
+    });
     notification.setTransient(true);
     source.addNotification(notification);
 }
index 11e57150b31a233d4e57f45ef7e764fb9b730386..9d9aaaef0faf23be3a1e81801db4d7a917b1deba 100644 (file)
@@ -351,28 +351,13 @@ class Action extends GObject.Object {
 });
 
 export class Notification extends GObject.Object {
-    _init(source, title, banner, params) {
-        super._init({source});
+    constructor(params) {
+        super(params);
 
-        this.title = title;
-        this.urgency = Urgency.NORMAL;
-        // 'transient' is a reserved keyword in JS, so we have to use an alternate variable name
-        this.isTransient = false;
-        this.privacyScope = PrivacyScope.USER;
-        this.forFeedback = false;
-        this.body = null;
-        this.useBodyMarkup = false;
-        this.sound = null;
-        this._soundPlayed = false;
-        this.actions = [];
-        this.setResident(false);
-
-        // If called with only one argument we assume the caller
-        // will call .update() later on. This is the case of
-        // NotificationDaemon, which wants to use the same code
-        // for new and updated notifications
-        if (arguments.length !== 1)
-            this.update(title, banner, params);
+        this._actions = [];
+
+        if (!this.datetime)
+            this.datetime = GLib.DateTime.new_now_local();
     }
 
     // update:
@@ -415,6 +400,10 @@ export class Notification extends GObject.Object {
         this.emit('updated', params.clear);
     }
 
+    get actions() {
+        return this._actions;
+    }
+
     get iconName() {
         if (this.gicon instanceof Gio.ThemedIcon)
             return this.gicon.iconName;
@@ -472,18 +461,18 @@ export class Notification extends GObject.Object {
 
             this.destroy();
         });
-        this.actions.push(action);
+        this._actions.push(action);
         this.emit('action-added', action);
     }
 
     clearActions() {
-        if (this.actions.length === 0)
+        if (this._actions.length === 0)
             return;
 
-        this.actions.forEach(action => {
+        this._actions.forEach(action => {
             this.emit('action-removed', action);
         });
-        this.actions = [];
+        this._actions = [];
     }
 
     setUrgency(urgency) {
index ed3f587202fb45ca406b2ea53790153e5e1578b1..a3b46b863d148e014278b88a8105490c5eb08dc3 100644 (file)
@@ -175,7 +175,7 @@ class FdoNotificationDaemon {
                 ? this._getSourceForApp(sender, app)
                 : this._getSourceForPidAndName(sender, pid, appName);
 
-            notification = new MessageTray.Notification(source);
+            notification = new MessageTray.Notification({source});
             this._notifications.set(id, notification);
             notification.connect('destroy', (n, reason) => {
                 this._notifications.delete(id);
@@ -405,8 +405,8 @@ const PRIORITY_URGENCY_MAP = {
 
 const GtkNotificationDaemonNotification = GObject.registerClass(
 class GtkNotificationDaemonNotification extends MessageTray.Notification {
-    _init(source, id, notification) {
-        super._init(source);
+    constructor(source, id, notification) {
+        super({source});
         this._serialized = GLib.Variant.new('a{sv}', notification);
         this.id = id;
 
index 32a9df89d51dfc2984cda3f0d4db0fbdb3e003c8..b16f5a26b0b5bce42f5024781a3b8d628808ce67 100644 (file)
@@ -39,7 +39,10 @@ class ShellInfo {
         let forFeedback = options.forFeedback;
 
         if (!this._notification) {
-            this._notification = new MessageTray.Notification(source, text, null);
+            this._notification = new MessageTray.Notification({
+                source,
+                title: text,
+            });
             this._notification.setTransient(true);
             this._notification.setForFeedback(forFeedback);
             this._notification.connect('destroy', () => delete this._notification);
index d19c6e7b915edff13196ad47a75925d91c5435dc..d65dc82f36213b0dff6be188e83264b87faf99e1 100644 (file)
@@ -2087,12 +2087,12 @@ export const ScreenshotUI = GObject.registerClass({
             title: _('Screenshot'),
             iconName: 'screencast-recorded-symbolic',
         });
-        const notification = new MessageTray.Notification(
+        const notification = new MessageTray.Notification({
             source,
             title,
             // Translators: notification body when a screencast was recorded.
-            this._screencastPath ? _('Click here to view the video.') : ''
-        );
+            body: this._screencastPath ? _('Click here to view the video.') : '',
+        });
         notification.setTransient(true);
 
         if (this._screencastPath) {
@@ -2329,14 +2329,15 @@ function _storeScreenshot(bytes, pixbuf) {
         title: _('Screenshot'),
         iconName: 'screenshot-recorded-symbolic',
     });
-    const notification = new MessageTray.Notification(
+    const notification = new MessageTray.Notification({
         source,
         // Translators: notification title.
-        _('Screenshot captured'),
+        title: _('Screenshot captured'),
         // Translators: notification body when a screenshot was captured.
-        _('You can paste the image from the clipboard.'),
-        {datetime: time, gicon: content}
-    );
+        body: _('You can paste the image from the clipboard.'),
+        datetime: time,
+        gicon: content,
+    });
 
     if (!disableSaveToDisk) {
         // Translators: button on the screenshot notification.
index 9188410a5e342481e00cc2766ea7f12022c34897..24a38c8b6dba725cfa4596b7c6fdb24d2fcf5173 100644 (file)
@@ -195,7 +195,7 @@ export class ShellMountOperation {
         this._notification?.destroy();
 
         const source = MessageTray.getSystemSource();
-        this._notification = new MessageTray.Notification(source, title, body);
+        this._notification = new MessageTray.Notification({source, title, body});
 
         this._notification.setTransient(true);
         this._notification.iconName = 'media-removable-symbolic';
index 86cfa95f8b059d9c938e2b7bddf58fdb1c232946..ae25af6f3cb910a66fb6686fa49fb2e01968ef73 100644 (file)
@@ -2030,9 +2030,11 @@ class Indicator extends SystemIndicator {
         this._notification?.destroy();
 
         const source = MessageTray.getSystemSource();
-        this._notification = new MessageTray.Notification(source,
-            _('Connection failed'),
-            _('Activation of network connection failed'));
+        this._notification = new MessageTray.Notification({
+            source,
+            title: _('Connection failed'),
+            body: _('Activation of network connection failed'),
+        });
         this._notification.iconName = 'network-error-symbolic';
         this._notification.setUrgency(MessageTray.Urgency.HIGH);
         this._notification.setTransient(true);
index 96d84d368e21e9434759e2a3c2ba9ee234f099a6..e70ca24353d18206012a12b522eb3c6ecdb58698 100644 (file)
@@ -258,7 +258,7 @@ class Indicator extends SystemIndicator {
             this._notification.destroy();
 
         const source = MessageTray.getSystemSource();
-        this._notification = new MessageTray.Notification(source, title, body);
+        this._notification = new MessageTray.Notification({source, title, body});
         this._notification.iconName = 'thunderbolt-symbolic';
         this._notification.setUrgency(MessageTray.Urgency.HIGH);
         this._notification.connect('destroy', () => {
index ee701394c2c36f0075ed8f094f6b0f764189c81a..7c3e53fbfab13304c901de175ac509137349c812 100644 (file)
@@ -37,9 +37,9 @@ export class WindowAttentionHandler {
         let source = new WindowAttentionSource(app, window);
         Main.messageTray.add(source);
 
-        let [title, banner] = this._getTitleAndBanner(app, window);
+        let [title, body] = this._getTitleAndBanner(app, window);
 
-        let notification = new MessageTray.Notification(source, title, banner);
+        let notification = new MessageTray.Notification({source, title, body});
         notification.connect('activated', () => {
             source.open();
         });
@@ -48,8 +48,8 @@ export class WindowAttentionHandler {
         source.addNotification(notification);
 
         window.connectObject('notify::title', () => {
-            [title, banner] = this._getTitleAndBanner(app, window);
-            notification.update(title, banner);
+            [title, body] = this._getTitleAndBanner(app, window);
+            notification.update(title, body);
         }, source);
     }
 }
index 5310a31b2efc5788bf12052b5f2459717016b088..712091f4da411e8350bb4aa00eaa3ae2c471ed1b 100644 (file)
@@ -56,8 +56,10 @@ export async function run() {
     source.connect('notification-request-banner',
         () => Scripting.scriptEvent('notificationShowDone'));
 
-    const notification = new MessageTray.Notification(source,
-        'A test notification');
+    const notification = new MessageTray.Notification({
+        source,
+        title: 'A test notification',
+    });
     source.addNotification(notification);
     await Scripting.sleep(400);